package com.gongpingjialoan.view;

import com.gongpingjialoan.R;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.NumberPicker;

public class NumberPickerDialog extends AlertDialog
{
    
    private boolean isClosed = false;
    
    View backviewV;
    
    OnDialogCallBack dialogCallBack;
    
    public static final int CANCLE = 1;
    
    public static final int YES = 2;
    
    NumberPicker picker;
    
    int minValue, maxValue;
    
    Button okB;
    
    long animduring = 250;
    
    int direction = 1;
    
    public NumberPickerDialog(Context context)
    {
        super(context);
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.num_picker_dialog);
        
        backviewV = findViewById(R.id.backview);
        backviewV.setOnClickListener(new View.OnClickListener()
        {
            
            @Override
            public void onClick(View v)
            {
                dismiss();
            }
        });
        
        picker = (NumberPicker)findViewById(R.id.num);
        picker.setMinValue(minValue);
        picker.setMaxValue(maxValue);
        
        okB = (Button)findViewById(R.id.ok);
        okB.setOnClickListener(new View.OnClickListener()
        {
            
            @Override
            public void onClick(View v)
            {
                if (dialogCallBack != null)
                {
                    dialogCallBack.onSelectResult(picker.getValue());
                }
                dismiss();
            }
        });
    }
    
    @SuppressLint("NewApi")
    public void onAttachedToWindow()
    {
        super.onAttachedToWindow();
//        playAnim();
    }
    
//    public void playAnim()
//    {
//        View v = findViewById(R.id.container);
//        AnimatorSet animatorSet = new AnimatorSet();
//        ObjectAnimator ani2 =
//            ObjectAnimator.ofFloat(v,
//                "translationY",
//                direction * 200,
//                -direction * 50,
//                direction * 30,
//                -direction * 10,
//                0).setDuration(animduring * 2);
//        ObjectAnimator ani1 = ObjectAnimator.ofFloat(v, "alpha", 0.2f, 1).setDuration(animduring);
//        animatorSet.play(ani1).with(ani2);
//        animatorSet.start();
//    }
    
    public int getMinValue()
    {
        return minValue;
    }
    
    public void setMinValue(int minValue)
    {
        this.minValue = minValue;
    }
    
    public int getMaxValue()
    {
        return maxValue;
    }
    
    public void setMaxValue(int maxValue)
    {
        this.maxValue = maxValue;
    }
    
    public OnDialogCallBack getDialogCallBack()
    {
        return dialogCallBack;
    }
    
    public void setDialogCallBack(OnDialogCallBack dialogCallBack)
    {
        this.dialogCallBack = dialogCallBack;
    }
    
    public interface OnDialogCallBack
    {
        void onSelectResult(int value);
    }
    
}
